package com.jdd.pedicure.fileter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class LoginFileter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = (String) request.getSession().getAttribute("username");
        if (StringUtils.isEmptyOrWhitespace(username)) {
            response.sendRedirect("/login");
            return false;
        }
        return true;// 只有返回true才会继续向下执行，返回false取消当前请求
    }

}
